package com.bjc.base.web;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.bjc.base.service.IBookService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.bjc.base.bean.request.BookReqVO;
import com.bjc.base.bean.response.BookVO;

/**
 * <p>
 * 绘本 前端控制器
 * </p>
 *
 * @author 许自辉
 * @since 2018-06-10
 */
@RestController
@RequestMapping("api/book")
@Api(value = "book-api", tags = { "绘本相关接口" })
public class BookController {

    @Autowired
    private IBookService bookService;

	@ApiOperation("分页查询绘本")
	@GetMapping("book/findPage")
	public ResultVO getBookPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			BookReqVO bookReqVO) {
		bookReqVO.setIsDel(0);
		PageHelper.startPage(pageNum, pageSize).setOrderBy(bookReqVO.getOrderByString());
		List<BookVO> bookVOs = bookService.getList(bookReqVO);
		return ResultGenerator.getSuccess(new PageInfo<BookVO>(bookVOs));
	}
	
	@ApiOperation("查询绘本")
	@GetMapping("book/find")
	public ResultVO getBook(BookReqVO bookReqVO) {
		BookVO bookVO = bookService.get(bookReqVO);
		return ResultGenerator.getSuccess(bookVO);
	}
	
	@ApiOperation("查询绘本分类数量")
	@GetMapping("bookGroupType/findList")
	public ResultVO getBookGroupType(BookReqVO bookReqVO) {
		List<BookVO> bookVO = bookService.getBookGroupType(bookReqVO);
		return ResultGenerator.getSuccess(bookVO);
	}

	@ApiOperation("添加绘本")
	@PostMapping("book/create")
	public ResultVO createBook(@RequestBody BookReqVO bookReqVOs) {
		int count = bookService.insert(bookReqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新绘本")
	@PutMapping("book/update")
	public ResultVO updateBook(@RequestBody BookReqVO bookReqVOs) {
		int count = bookService.update(bookReqVOs);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("批量删除绘本")
	@DeleteMapping("book/deleteList")
	public ResultVO deleteBook(@ApiParam(value = "book id集合") @RequestBody int[] ids) {
		int count = bookService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}

}
